import React, { useEffect, useState } from 'react';

import qs from 'qs';

import request from '@/http';

//搜索框取值   localStorage存储
const getCollage = async () => {
  console.log('getCollage');
  const chooseCollege: any = await request.post(
    '/api/common_module/a_t_s/getCollege',
  );
  console.log(chooseCollege);
  const cCollege = chooseCollege.data.map((user: any) => ({
    key: `user_${user.collegeId}`,
    id: user.collegeId,
    collegeId: user.collegeId,
    collegeName: user.collegeName,
  }));
  localStorage.setItem('collegesName', JSON.stringify(cCollege));
};

const getMajor = async () => {
  const chooseMajor: any = await request.post(
    '/api/common_module/a_t_s/getMajor',
  );
  console.log(1111);
  const cMajor = chooseMajor.data.map((user: any) => ({
    key: `user_${user.majorId}`,
    id: user.majorId,
    majorId: user.majorId,
    majorName: user.majorName,
  }));
  localStorage.setItem('major', JSON.stringify(cMajor));
};

const getGrade = async () => {
  const chooseGrade: any = await request.post(
    '/api/common_module/a_t_s/getGrade',
  );
  console.log(chooseGrade);
  const cGrade = chooseGrade.data.map((user: any) => ({
    key: `user_${user.gradeId}`,
    id: user.gradeId,
    gradeId: user.gradeId,
    gradeName: user.gradeName,
  }));
  localStorage.setItem('gradeName', JSON.stringify(cGrade));
};

const getClasses = async () => {
  const chooseClass: any = await request.post(
    '/api/common_module/a_t_s/getClassInfo',
  );
  console.log(chooseClass);
  const cClass = chooseClass.data.map((user: any) => ({
    key: `user_${user.classId}`,
    id: user.classId,
    classId: user.classId,
    className: user.className,
  }));

  localStorage.setItem('classname', JSON.stringify(cClass));
};

//班主任

//
const getTeacher = async () => {
  const chooseTeacher: any = await request.post(
    '/api/common_module/a_t_s/getTeacher',
  );

  const cTeacher = chooseTeacher.data.map((user: any) => ({
    key: `user_${user.teacherId}`,
    id: user.teacherId,
    teacherId: user.teacherId,
    teacherName: user.teacherName,
  }));

  localStorage.setItem('teacher', JSON.stringify(cTeacher));
};

const getCourse = async () => {
  const chooseCourse: any = await request.post(
    '/api/common_module/a_t_s/getCourse',
  );

  const cCourse = chooseCourse.data.map((user: any) => ({
    key: `user_${user.courseId}`,
    id: user.courseId,
    courseId: user.courseId,
    courseName: user.courseName,
  }));

  localStorage.setItem('course', JSON.stringify(cCourse));
};

const getTeam = async () => {
  const chooseTeam: any = await request.post(
    '/api/common_module/a_t_s/getTeam',
  );
  console.log(chooseTeam);
  const cTeam = chooseTeam.data.map((user: any) => ({
    key: `user_${user.teamId}`,
    id: user.teamId,
    teamId: user.teamId,
    teamName: user.teamName,
  }));
  localStorage.setItem('team', JSON.stringify(cTeam));
};

export {
  getCollage,
  getTeacher,
  getClasses,
  getGrade,
  getMajor,
  getCourse,
  getTeam,
};
